package net.keebook.webapp.util;

import java.util.Date;
import java.util.TimeZone;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class TimeConverter implements Converter {
	@Override
	public Object getAsObject(FacesContext context, UIComponent uiComponent, String s) {
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent uiComponent, Object o) {
		if (o instanceof Date) {
			TimeZone localTimezone = TimeZone.getTimeZone((String)uiComponent.getValueExpression("timezone").getValue(context.getELContext()));
			String pattern = "EEE, MMM d, yyyy HH:mm:ss";
			return DateUtil.getLocalFormattedDateFromUtcTimestamp((Date)o, localTimezone, pattern);
		}
		return "";
	}
}
